package a07_二叉树;

/**
 * <p>
 * a31_修剪二叉搜索树复习1
 * </p>
 *
 * @author flyduck
 * @since 2024/12/27
 */
public class a31_修剪二叉搜索树复习1 {
    public TreeNode trimBST(TreeNode currentNode, int low, int high) {
        if (currentNode == null) {
            return null;
        }

        if(currentNode.val < low){
            return trimBST(currentNode.right, low, high);
        }else if(currentNode.val > high){
            return trimBST(currentNode.left, low, high);
        }else {
            currentNode.left = trimBST(currentNode.left, low, high);
            currentNode.right = trimBST(currentNode.right, low, high);
            return currentNode;
        }
    }
}
